<?php
session_start();
include_once("system/system.php");
@header("Content-Type:text/html;charset=UTF-8");
if (!$home["theme"] && !file_exists('/theme/'.$home["theme"].'/index.php')){
    $theme='9gyun';
}else{
    $theme=$home["theme"];
}
$ip=real_ip();

try{
    $counttjs=count($pdo->query("SELECT * FROM 9g_msg")->fetchAll());
    function counttj($id){
        global $pdo;
        return count($pdo->query("SELECT * FROM 9g_msg WHERE `type`='{$id}'")->fetchAll());
    }

    function type_if($type){
        global $pdo;
        return $pdo->query("SELECT * FROM 9g_type WHERE `id`='{$type}'")->fetch()["type"];
    }


}catch(Exception $e){

}
if(isset($_COOKIE["user"])){
    $token=authcode($_COOKIE["user"],'DECODE','codecj80808');
    $k=explode("##",$token);
    $query=$pdo->prepare("SELECT * FROM 9g_user WHERE `username`=:username and `password`=:password ");
    $query->bindParam(":username",$k[0],PDO::PARAM_STR);
    $query->bindParam(":password",$k[1],PDO::PARAM_STR);
    $query->execute();
    if($query->rowCount()>=1){
        $login=1;
    }
}else{
    $login=0;
}
$_GET["mod"]==null ? header("Location:index.php?mod=index") : '';
switch ($_GET["mod"]){
    case 'index':
        $tjquery=$pdo->query("SELECT * FROM 9g_type");
        while($row=$tjquery->fetch()){
            $tjdata.='   <button style="margin-top:5px;" onclick="window.location.href=\'index.php?mod=bank&id='.$row["id"].'\';" class="btn btn-outline-info">
            <div  class="d-flex">
                <div class=" me-3 align-self-center"><img class="rounded-circle" alt="" height="20px;" src="assets/image/tj.gif"></div>
                <div class="flex-grow-1 overflow-hidden">
                    <h5 class="font-size-14 mb-1"></h5>
                    <p class="text-truncate mb-0">'.$row["type"].'收录信息个数 </p>
                </div>
                <div class="flex-shrink-0 font-size-13">'.counttj($row["id"]).'个 </div>
            </div>
        </button>';
        }
        $ggquery=$pdo->query("SELECT * FROM 9g_aounce");
        while($row=$ggquery->fetch()){
            $ggdata.=' <button onclick="window.location.href=\'index.php?mod=aounce&id='.$row["id"].'\'" data-bs-toggle="modal" data-bs-target=".cc-example-modal-center" style="margin-top:5px;"  class="btn btn-outline-danger">
            <div class="d-flex">
                <div class=" me-3 align-self-center"><img class="rounded-circle" alt="" height="20px;" src="'.$row["image"].'"></div>
                <div class="flex-grow-1 overflow-hidden">
                    <h5 class="font-size-14 mb-1"></h5>
                    <p class="text-truncate mb-0">'.$row["title"].'</p>
                </div>
                <div class="flex-shrink-0 font-size-13">'.$row["date"].'</div>
            </div>
        </button>';
        }
        $ggquery=null;
        $tjquery=null;
        include './theme/'.$theme.'/index.php';
        break;
        case 'jubao':
            include './theme/'.$theme.'/jubao.php';
            break;
    case 'bank':
           function data_act($data){
                   $s=explode("||",$data);
                   foreach($s as $k=>$v){
                    $x.=$v.'<br>';
                     }
                    return $x;
                     }
        if(isset($_GET["id"])){
                
            $id=daddslashes($_GET["id"]);
            $typename=type_if($id).'-';
            $slquery=$pdo->prepare("SELECT * FROM 9g_msg WHERE `type`=:id and `status`='1'");
            $slquery->execute([":id"=>$id]);
        }else{
            $slquery=$pdo->query("SELECT * FROM 9g_msg WHERE `status`='1'");
        }
        while($row=$slquery->fetch()){
            $sldata.=' <button onclick="return zsy('.$row["id"].')" data-bs-toggle="modal" data-bs-target=".cc-example-modal-center" style="margin-top:5px;"  class="btn btn-outline-danger">
            <div class="d-flex">
                <div class=" me-3 align-self-center">
                <div class="flex-grow-1 overflow-hidden">
                    <h5 class="font-size-14 mb-1"></h5>
                    <p class="text-truncate mb-0"><a href="#" class="badge bg-info">'.type_if($row["type"]).'</a><br>'.data_act($row["data"]).'</p>
                </div>
                <div class="flex-shrink-0 font-size-13">'.$row["date"].'</div>
            </div>
        </button>';
        }
        $slquery=null;
            include 'theme/'.$theme.'/bank.php';
            break;
    case 'login':
        if($login==1)exit("<script>alert('你已经登录过了');location.href='index.php?mod=index';</script>");
        include 'theme/'.$theme.'/login.php';
        break;
    case 'logout':
        setcookie("user", "", time() - 3600 * 72);
        exit("<script>alert('已退出登录');location.href='index.php?mod=index';</script>");
        break;
    case 'youlian':
          $ylquery=$pdo->query("SELECT * FROM 9g_you WHERE `status`='1'");
        while($row=$ylquery->fetch()){
            $youlist.='<div onclick="window.location.href=\'http://'.$row["url"].'/\'" class="col-6">
        <div class="social-source text-center mt-3">
            <div class="avatar-xs mx-auto mb-3"><span class="rounded-circle"><img style="width:40px;height:40px;" src="'.$row["favicon"].'"></span></div>
            <h5 class="font-size-15">'.$row["name"].'</h5>
              <p class="text-muted mb-0">'.$row["url"].'</p>
        </div>
    </div>';
        }
        $ylquery=null;
         include 'theme/'.$theme.'/youlian.php';
        break;
            case 'aounce':
        if(isset($_GET["id"])){
        $ggquery=$pdo->query("SELECT * FROM 9g_aounce");
        while($row=$ggquery->fetch()){
            $ggdata.=' <button onclick="window.location.href=\'index.php?mod=aounce&id='.$row["id"].'\'" data-bs-toggle="modal" data-bs-target=".cc-example-modal-center" style="margin-top:5px;"  class="btn btn-outline-danger">
            <div class="d-flex">
                <div class=" me-3 align-self-center"><img class="rounded-circle" alt="" height="20px;" src="'.$row["image"].'"></div>
                <div class="flex-grow-1 overflow-hidden">
                    <h5 class="font-size-14 mb-1"></h5>
                    <p class="text-truncate mb-0">'.$row["title"].'</p>
                </div>
                <div class="flex-shrink-0 font-size-13">'.$row["date"].'</div>
            </div>
        </button>';
        }
        $ggquery=null;
            $id=daddslashes($_GET["id"]);
            $query=$pdo->prepare("SELECT * FROM 9g_aounce WHERE `id`=:id");
            $query->bindParam(":id",$id,PDO::PARAM_INT);
            $query->execute();
            $msg=$query->fetch();
            $aounce=$msg["aounce"];
            $title=$msg["title"];
            $image=$msg["image"];
             $query=null;
            include 'theme/'.$theme.'/aounce.php';
        }
       
            break;
}
$pdo=null;
?>